package com.example.fms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.fms.dto.req.GoodsReqDto;
import com.example.fms.dto.req.OrdersReqDto;
import com.example.fms.dto.resp.GoodsRespOneDto;
import com.example.fms.dto.resp.OrdersRespDto;
import com.example.fms.dto.resp.OrdersRespOneDto;
import com.example.fms.service.GoodsService;
import com.example.fms.service.OrdersService;
import com.example.fms.vo.ResponseBean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Resource
    private OrdersService ordersService;
    @GetMapping()
    public ResponseBean<Page<OrdersRespOneDto>> getOrdersPage(@RequestParam(value = "query", required = false) String query ,
                                                              @RequestParam(value = "pagenum", defaultValue = "1") Integer pagenum,
                                                              @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize) {
        OrdersReqDto req = new OrdersReqDto();
        req.setOrder_number(query);
        req.setPageNum(pagenum);
        req.setPageSize(pagesize);
        return ResponseBean.successMeat(ordersService.getOrdersPage(query,req));
    }

    @PutMapping("/{id}")
    public ResponseBean<Boolean> putOrdersById(@RequestBody OrdersReqDto req, @PathVariable Long id) {
        return ResponseBean.successMeat(ordersService.putOrdersById(req, id));
    }


    @GetMapping("/{id}")
    public ResponseBean<OrdersRespOneDto> getOrdersById(@PathVariable Long id) {
        return ResponseBean.successMeat(ordersService.getOrdersById(id));
    }


    @PutMapping("/{id}/address")
    public ResponseBean<Boolean> putAddressById(@PathVariable Long id , @RequestParam(value = "consignee_addr") Integer consignee_addr) {
        return ResponseBean.successMeat(ordersService.putAddressById(id, consignee_addr));
    }

}
